import { useRoute, useRouter, createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import axios from 'axios'
import Home from '@/pages/home/Home'
// import Register from '@/pages/auth/Register'
import Login from '@/pages/Login/Login'
import test from '../test.vue'
import test2 from '../test2.vue'

export const router = createRouter({
    setup () {
  
      return {}
    },
    history: createWebHistory(),// 采用hash 模式 createWebHistory
    routes: [
        // {
        //     path: '/aweirunner/register',
        //     name: 'Register',
        //     component: Register,
        //     meta: {
        //         title: '用户注册'
        //     }
        // }, 
        {
            path: '/aweirunner/login',
            name: 'Login',
            component: Login,
            meta: {
                title: '用户登录'
            }
        }, 
        {
            name: 'ReportDetail',
            path: '/reportDetail/:id',
            component: ()=>import("../pages/reports/ReportDetail.vue"),

            meta: {
                title: '报告详情',
                requireAuth: true
            }

        },
        {
            path: '/test',
            name: 'test',
            component: test,
            meta: {
                title: '测试'
            }
        }, 
        
        // {
        //     path: '/test2',
        //     name: 'test2',
        //     component: test2,
        //     meta: {
        //         title: '测试2'
        //     }
        // }, 
        {

            path: '/aweirunner',
            name: 'Index',
            component: Home,
            meta: {
                title: '首页',
                requireAuth: true
            },
            children: [
                {
                    name: 'ProjectList',
                    path: 'project_list',
                    component: ()=>import("../pages/project/ProjectList.vue"),
                    meta: {
                        title: '项目列表',
                        requireAuth: true,
                    }
                },                
                {
                    name: 'ProjectDetail',
                    path: 'project/:id/dashbord',
                    component: ()=>import("../pages/project/ProjectDetail.vue"),
                    meta: {
                        title: '项目预览',
                        requireAuth: true,
                    }

                },
                {
                    name: 'RecordApi',
                    path: 'api_record/:id',
                    component: ()=>import("../pages/aweirunner/api/RecordApi.vue"),
                    meta: {
                        title: '接口模板',
                        requireAuth: true
                    }

                },
                {
                    name: 'RecordConfig',
                    path: 'record_config/:id',
                    component: ()=>import("../pages/aweirunner/config/RecordConfig.vue"),
                    meta: {
                        title: '配置管理',
                        requireAuth: true
                    }

                },
                {
                    name: 'GlobalEnv',
                    path: 'global_env/:id',
                    component: ()=>import("../pages/variables/GlobalEnv.vue"),
                    meta: {
                        title: '全局变量',
                        requireAuth: true
                    }

                },
                {
                    name: 'Task',
                    path: 'tasks/:id',
                    component: ()=>import("../pages/task/Tasks.vue"),

                    meta: {
                        title: '定时任务',
                        requireAuth: true
                    }

                },
                {
                    name: 'Reports',
                    path: 'reports/:id',
                    component: ()=>import("../pages/reports/ReportList.vue"),

                    meta: {
                        title: '历史报告',
                        requireAuth: true
                    }

                },

            ]
        },
        {
          path:'/',
          redirect:'/aweirunner/project_list'   
      },

    ]
})



  
//   router.beforeEach((to,from,next)=>{
//     if(to.meta.requireAuth)
//     {
//         next();
//         //       var user=sessionStorage.getItem("user")? JSON.parse(sessionStorage.getItem("user")) : null
//         //       var UserType=window.sessionStorage.getItem("role")
//         //       console.log(UserType)
//         //       if(user!=null)
//         //       {
//         //         if(UserType=="sponsor"&&to.path.indexOf("sponsor")>0)
//         //         {
//         //           next();
//         //         }
//         //         else if(to.path.indexOf("main")>0&&UserType=='admin'||UserType=="super-admin")
//         //         {
//         //             next();
//         //         }
//         //         else if(to.path.indexOf("mainself")>0){
//         //           next();
//         //         }
//         //       }
              
//         //       console.log("登录失效或还未登录")
//         //       next({
//         //           path:'/login',
//         //           query:{
//         //             // 把目标界面的路径作为参数传入，方便登录后跳转
//         //               redirect:to.fullPath,
//         //               posturl:to.query.posturl
//         //           }
//         //       })
//         }
//         else
//         {
//             next()
//         }
//   })
  // 引入的useRoute,useRouter 相当于vue2的 this.$route()，this.$router()
  export default router;